﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


namespace Kooboo.Commerce.Promotions.Cashback
{
    internal class Context
    {
        public Context()
        {
            this.DataContext = new CashbackDataContext(Kooboo.Commerce.Configuration.FindConnection());
        }

        public CashbackDataContext DataContext
        {
            get;
            set;
        }

        public Promotion_Cashback Find(IPromotionRule rule)
        {
            return DataContext.Promotion_Cashbacks.Where(i => i.PromotionRuleId == rule.Id).FirstOrDefault();
        }

        public void Remove(IPromotionRule rule)
        {
          

            var items = DataContext.Promotion_Cashbacks.Where(i => i.PromotionRuleId == rule.Id);

            DataContext.Promotion_Cashbacks.DeleteAllOnSubmit(items);

            DataContext.SubmitChanges();

        }
    }
}